import Vue from 'vue'
import App from './App.vue'
import routes from './routers'
import VueRouter from 'vue-router'
import {useElementUI} from "@/ui/elment";
import VueQuillEditor from 'vue-quill-editor'
import store from './store'
import Echarts from "vue-echarts";
import 'echarts'

// require styles 导入富文本编辑器对应的样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import {getUserInfo} from "@/api";

Vue.prototype.$store = store;
Vue.use(VueQuillEditor, /* { default global options } */)
useElementUI(Vue)
Vue.config.productionTip = false
Vue.use(VueRouter)
Vue.component('VueEcharts',Echarts)
const router = new VueRouter({
  routes // (缩写) 相当于 routes: routes
})

router.beforeEach((to,from,next)=>{
  if(to.name==='登陆')next()
  if(store.state.userInfo===null){
    getUserInfo().then(res=>{
      if(res.status===200) {
        if(res.data.data) {
          store.commit('updateUserInfo', res.data.data)
          next();
        }else {
          next({name:'登陆'})
        }
      }
      else{
        next({name:'登陆'})
      }

    }).catch(()=>{
      next({name:'登陆'})
    })
  }else {
    next()
  }
})
new Vue({
  render: h => h(App),
  router
}).$mount('#app')



